package com.CAS;

import java.util.concurrent.atomic.AtomicInteger;

/**
     * CAS compareAndSet() 非阻塞一个线程的失败或者挂起不应该影响其他线程的失败或挂起的算法
 *  比较和转换
 * */
public class Demo1 {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(2020);

        //期望值达到就更新，否则不更新。
        //public final boolean compareAndSet(int expect, int update)
        atomicInteger.compareAndSet(2020,2025);
        System.out.println(atomicInteger.get());
        atomicInteger.compareAndSet(2021,2020);
        System.out.println(atomicInteger.get());
    }
}
